/*The STATA code below merges together the 1987-99 and 2000-15 data files to create the master 1987-2015 file. This STATA code creates new variables that 
  adjust revenue and spending data by full-time equivalent enrollment, creating revenue and spending variables "per FTE" (denoted as "_fte").  In addition, 
  these new FTE-adjusted variables are inflated into 2013 dollars using the CPI-U scalar (denoted as "_fte_cpi").*/

cd "/*ENTER YOUR FILE PATH HERE*/"

use delta_public_release_87_99 
merge 1:1 groupid academicyear using delta_public_release_00_15 
save delta_public_release_87_15, replace

use delta_public_release_87_15, clear

	/*Create per-FTE and CPI-adjusted variables*/	
	foreach var in tuition01 tuition02 tuition03 nettuition01 net_student_tuition federal03 state03 local03 state_local_app federal07 federal07_net_pell ///
				   state06 local06 federal10 federal10_net_pell state09 fed_state_loc_grants_con private03 affiliate01 investment01 endowment03 ///
				   priv_invest_endow edactivity03 auxiliary03 hospital03 other03 other04 independent03 other05 auxother_rev stable_operating_rev ///
				   total03_revenue tot_rev_wo_auxother_sum tot_rev_w_auxother_sum unrestricted_revenue restricted_revenue appliedaid01 appliedaid02 ///
				   grant01 grant02 grant03 grant04 grant05 grant06 grant07 institutional_grant_aid ///
				   instruction01 instruction02 research01 research02 pubserv01 pubserv02 acadsupp01 acadsupp02 studserv01 studserv02 instsupp01 instsupp02 ///
				   opermain01 opermain02 depreciation01 grants01u grants01r grants01 auxiliary01 auxiliary02 hospital01 hospital02 independ01 independ02 ///
				   otheroper01 otheroper02 totaloper01 totaloper02 totaloper03 totaloper04 totaloper05 interest01 othernon01 othernon02 ///
				   other01 other02 totalnon01 totalnon02 total01 total02 total03_expenses total04 total05 total06 total07 ///
				   eandg01 eandg01_sum eandg01_w_auxother_sum eandg02 eandg03 eandg03a eandg03b eandg04 eandg05 eandg06 eandg07 eandg08 ///
				   rschpub01 acadinststud01 acadinstsupp01 other_ed_related_cost eandr research_related_cost pubserv_related_cost research_pubserv_grants ///
				   auxother_cost sticker_subsidy average_subsidy gross_auxiliary_margin gross_operating_margin {
		gen `var'_fte=`var'/fte_count
	}
	gen state_local_grant_con_fte=(state_local_grant_contract/fte_count)
		
	foreach var in tuition01 tuition02 tuition03 nettuition01 net_student_tuition federal03 state03 local03 state_local_app federal07 federal07_net_pell ///
				   state06 local06 federal10 federal10_net_pell state09 fed_state_loc_grants_con private03 affiliate01 investment01 endowment03 ///
				   priv_invest_endow edactivity03 auxiliary03 hospital03 other03 other04 independent03 other05 auxother_rev stable_operating_rev ///
				   total03_revenue tot_rev_wo_auxother_sum tot_rev_w_auxother_sum unrestricted_revenue restricted_revenue appliedaid01 appliedaid02 ///
				   grant01 grant02 grant03 grant04 grant05 grant06 grant07 institutional_grant_aid ///
				   instruction01 instruction02 research01 research02 pubserv01 pubserv02 acadsupp01 acadsupp02 studserv01 studserv02 instsupp01 instsupp02 ///
				   opermain01 opermain02 depreciation01 grants01u grants01r grants01 auxiliary01 auxiliary02 hospital01 hospital02 independ01 independ02 ///
				   otheroper01 otheroper02 totaloper01 totaloper02 totaloper03 totaloper04 totaloper05 interest01 othernon01 othernon02 ///
				   other01 other02 totalnon01 totalnon02 total01 total02 total03_expenses total04 total05 total06 total07 ///
				   eandg01 eandg01_sum eandg01_w_auxother_sum eandg02 eandg03 eandg03a eandg03b eandg04 eandg05 eandg06 eandg07 eandg08 ///
				   rschpub01 acadinststud01 acadinstsupp01 other_ed_related_cost eandr research_related_cost pubserv_related_cost research_pubserv_grants ///
				   auxother_cost sticker_subsidy average_subsidy gross_auxiliary_margin gross_operating_margin {
		gen `var'_fte_cpi=(`var'/fte_count)/cpi_scalar_2015
	}
		gen state_local_grant_con_fte_cpi=(state_local_grant_contract/fte_count)/cpi_scalar_2015
		
save, replace		
		
		